<script>
//公共的列表页
$(document).ready(function(){
	{params}
	var c = {
		num:'',
		cnum:'',
		pnum:'',
		atype:'',
		gtype:'',
		funitid:'',
		init:function(){
			this.num 	= params.num;
			if(params.cnum)this.cnum 	= params.cnum;
			if(params.pnum)this.pnum 	= params.pnum;
			if(params.atype)this.atype 	= params.atype;
			if(params.gtype)this.gtype 	= params.gtype;
			if(params.sqlwhere)this.sqlwhere 	= params.sqlwhere;
			if(params.funitid)this.funitid = params.funitid;
			
			this.resize();
			importjs('list', function(){
				c.createlist();
			});
		},
		resize:function(){
			var sid = 'view_{rand}';
			if(params.height){
				$('#'+sid+'').css('height',''+params.height+'px');
			}else{
				var meih = viewheight-22;
				xcy.setheight(sid, meih);
			}
		},
		createlist:function(){
			var url = 'api/flow/listinit?num='+this.num+'';
			if(this.pnum)url+='&pnum='+this.pnum+'';
			js.ajax.get({
				url:url,
				cnum:this.cnum,
				funitid:this.funitid,
				onsuccess:function(ret){
					c.loadshow(ret.data);
				},
				onerror:function(ret){
					$('#view_{rand}').html(ret.msg);
				}
			});
		},
		loadshow:function(da){
			if(da.isadd==1)this.addshow();
			this.initdata= da;
			this.showatype(da.atypearr);
			this.listobj = new js.list.create({
				view:'view_{rand}',
				num:this.num,
				cnum:this.cnum,
				pnum:this.pnum,
				funitid:this.funitid,
				atype:this.atype,
				gtype:this.gtype,
				sqlwhere:this.sqlwhere,
				modejs:da.modejs,
				moders:da.moders,
				isadd:da.isadd,
				optobj:this,
				params:params,
				rand:'{rand}'
			})
			$('#key_{rand}').keydown(function(e){
				if(e.keyCode==13)c.search();
			});
		},
		showatype:function(da){
			var i,len=da.length,d,s='',act;
			this.atypediv = 'atypediv_{rand}';
			for(i=0;i<len;i++){
				act = '';
				d 	= da[i];
				if(i==0 || this.atype==d.num){
					act=' active';
					this.atype = d.num;
				}
				s+='<button type="button" clickevt="changeatype,'+d.num+'" class="webbtn webbtn-default'+act+'">'+d.name+'</button>';
			}
			if(s){
				$('#'+this.atypediv+'').html(s).show();
				js.initbtn(this,this.atypediv);
			}
		},
		changeatype:function(o1,lx){
			$('#'+this.atypediv+'').find('button').removeClass('active');
			$(o1).addClass('active');
			this.atype = lx;
			if(this.listobj)this.listobj.setparams({atype:lx});
		},
		addshow:function(){
			$('#toolleft_{rand}').show();
		},
		addhide:function(){
			$('#toolleft_{rand}').hide();
		},
		adds:function(o1){
			this.listobj.addmenu(o1)
		},
		add:function(){
			this.listobj.addopen(true);
		},
		search:function(){
			if(this.listobj)this.listobj.search(get('key_{rand}').value);
		},
		searchhei:function(o){
			if(!this.initdata)return;
			var da = [];
			if(this.initdata.isdaochu==1)da.push({name:'导出',lx:1});
			if(this.initdata.isdaoru==1)da.push({name:'导入',lx:2});
			importjs('menu','create', {
				obj:$(o),data:da,
				onclick:function(d1){
					
				}
			});
		},
		daochu:function(){
			
		},
		showleft:function(st){
			$('#viewleft_{rand}').show();
			xcy.setheight('viewcont_{rand}', viewheight-12);
			$('#viewlefttitle_{rand}').html(st);
		},
		leftcontid:function(){
			return 'viewcont_{rand}';
		},
		addright:function(s,o){
			$('#toolcetner_{rand}').after('<td nowrap style="padding-left:10px">'+s+'</td>');
			if(o)js.initbtn(o, 'viewmain_{rand}');
		},
		addbtn:function(btn,evt, o, ys){
			if(!ys)ys='webbtn-default';
			var s='<button class="webbtn '+ys+'" clickevt="'+evt+'" type="button">'+btn+'</button>';
			this.addright(s, o);
		},
		shideleft:function(){
			$('#viewleft_{rand}').hide();
			$('#btnleft_{rand}').show();
		},
		sshowleft:function(){
			$('#viewleft_{rand}').show();
			$('#btnleft_{rand}').hide();
		}
	}
	js.initbtn(c);
});
</script>
<table width="100%"><tr valign="top">
	
	<td style="display:none" id="viewleft_{rand}">
	<div class="rock-panel rock-border rock-radius" style="width:210px;overflow:hidden;margin-right:8px;">
		<div class="rock-panel-title">
			<span id="viewlefttitle_{rand}">选项</span>
			<a style="float:right" clickevt="shideleft"><i class="icon-caret-left"></i></a>
		</div>
		<div style="height:400px;overflow:auto" id="viewcont_{rand}"></div>
	</div>
	</td>
	
	<td width="100%">
	<div class="rock-panel rock-border rock-radius" id="viewmain_{rand}">
		<div style="padding:10px">
			<div>
				<table width="100%"><tr>
				<td style="padding-right:10px;display:none" id="btnleft_{rand}"><a style="float:right" clickevt="sshowleft"><i class="icon-caret-right"></i></a></td>
				<td id="toolleft_{rand}" nowrap style="padding-right:10px;display:none">
					<span class="webbtn-group">
					<button class="webbtn" clickevt="add" type="button">新增</button><button class="webbtn" clickevt="adds" type="button"><i class="icon-angle-down"></i></button>
					</span>
				</td>
				
				<td id="toolsearch_{rand}" nowrap style="padding-right:10px">
					<span class="webbtn-group">
					<input class="input" style="width:150px" id="key_{rand}" placeholder="关键词搜索"><button class="webbtn webbtn-default" clickevt="search" type="button" style="border-left-width:0">搜索</button><button class="webbtn webbtn-default" clickevt="searchhei" type="button"><i class="icon-angle-down"></i></button></span>
				</td>
				<td id="atypediv_{rand}" class="webbtn-group" nowrap style="padding-right:10px;display:none">
				
				</td>
				<td width="100%" id="toolcetner_{rand}">
					
				</td>
				</tr></table>
			</div>
			<div class="blank10"></div>
			<div id="view_{rand}" style="height:300px;overflow:hidden;">
				<div align="center" style="padding-top:50px" ><i style="height:40px;width:40px" class="rock-loading"></i></div>
			</div>
		</div>
	</div>
	</td>

</tr></table>